package rd.hardcore.ui.config.content 
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.TextEvent;
	import flash.utils.Dictionary;
	import fr.digitas.flowearth.conf.Conf;
	import rd.hardcore.ui.config.content.boards.BoardsContent;
	import rd.hardcore.ui.config.nav.Nav;
	import rd.hardcore.ui.config.tpl.ConfigContact;
	import rd.hardcore.ui.config.tpl.ConfigGeneral;
	import rd.hardcore.ui.config.tpl.ConfigHelp;
	import rd.hardcore.ui.config.tpl.ConfigSounds;
	/**
	 * ...
	 * @author Romain
	 */
	public class ConfigPanelContent extends Sprite
	{
		
		static public var isTweening : Boolean;
		
		public var proxyNav	: Nav;
		
		private var currentTpl 	: BaseContent;
		private var oldTpl 		: BaseContent;
		
		private var tabItems	: Vector.<BaseContent>;
		private var itemsById	: Dictionary;
		
		public function ConfigPanelContent() 
		{
			y = 10;
			x = 170;
			
			itemsById = new Dictionary();
			tabItems = new Vector.<BaseContent>();			
		}
		
		/* Building */
		public function build() : void
		{
			
			var data 	: XML = Conf.getDatas("config");
			var tpl 	: BaseContent;
			
			for each( var node : XML in data.children() )
			{
				switch( String(node.@id) )
				{
					case "general":
						tpl = new ConfigGeneral();
						break;
					case "boards":
						tpl = new BoardsContent();
						break;
					case "sounds":
						tpl = new ConfigSounds();
						break;
					case "help":
						tpl = new ConfigHelp();
						break;
					case "contact":
						tpl = new ConfigContact();
						break;
				}
				
				if ( node.@default.length() > 0) 
					oldTpl = currentTpl = tpl;
				
				tpl.build( node );
				tabItems.push( tpl );
				itemsById[ tpl.id ] = tpl;
				
			}
			
			currentTpl.display();
			addChild(currentTpl);
			
		}
		
		public function update ( evt : TextEvent) : void
		{	
			if (oldTpl) oldTpl.hide( clear );
			
			currentTpl = itemsById[ evt.text ] as BaseContent;
			
			
			addChild(currentTpl);
			currentTpl.display();
		}
		
		private function clear() : void
		{
			if ( contains(oldTpl) ) removeChild( oldTpl );
			oldTpl = currentTpl;
		}
		
		
		
		
	}

}